<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公司名称">
              <a-input placeholder="请输入公司名称" v-model="queryParam.companyName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公司税号">
              <a-input placeholder="请输入公司税号" v-model="queryParam.taxNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
          <a-form-item label="认证状态">
            <j-dict-select-tag
              placeholder="请选择认证状态"
              v-model="queryParam.legalStatusId"
              dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =APPLY_LEGAL_STATUS"
            />
          </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="record.statusId == '2'&record.legalStatusId=='LEGAL_SUCCESS'">
                <a @click="handleUpdateEdit(record)">修改认证信息</a>
              </a-menu-item>
              <a-menu-item v-if="record.statusId == '2'&record.legalStatusId!='LEGAL_SUCCESS'">
                <a @click="handleCreateEdit(record)">填写认证信息</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <clmCompany-modal ref="modalForm" @ok="modalFormOk"></clmCompany-modal>

    <appro-modal :data2="data2" :apprVisible="apprVisible" @apprClose="apprVisible=false" ></appro-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ClmCompanyModal from './modules/ClmCompanyModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import ApproModal from '@/components/jeecg/modal/approModal'
  import { postAction,getAction } from '@/api/manage'
  export default {
    name: "ClmCompanyList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      ClmCompanyModal,
      ApproModal
    },
    data () {
      return {
        description: '合作伙伴表管理页面',
        dataParam: {
          statusId: '2',
          typeId:'Customer;Supplier;Internal',
        },
        data2:[],
        apprVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'公司名称',
            align:"center",
            dataIndex: 'companyName',
            sorter: (a, b) => a.companyName - b.companyName,
          },
          {
            title:'税号',
            align:"center",
            dataIndex: 'taxNumber',
            sorter: (a, b) => a.taxNumber - b.taxNumber,
          },
          {
            title:'法人姓名',
            align:"center",
            dataIndex: 'legalName',
            sorter: (a, b) => a.legalName - b.legalName,
          },
          {
            title:'法人身份证号',
            align:"center",
            dataIndex: 'legalIdCard',
            sorter: (a, b) => a.legalIdCard - b.legalIdCard,
          },
          {
            title:'认证状态',
            align:"center",
            dataIndex: 'legalStatusId_dictText',
            sorter: (a, b) => a.legalStatusId_dictText - b.legalStatusId_dictText,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/online/api/listClmCompany",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      handleSubmit(record) {
        let url = ''
        if(record.typeId == 'Cusomer'){
          url = this.url.createClmCusomerAdmitApproval
        }else{
          url = this.url.createClmSupplierAdmitApproval
        }
        getAction(url, { id: record.id }).then((res) => {
          if (res.success) {
            this.$message.success('提交成功')
            this.loadData()
          }
        })
      },
      async handleEsign(id){
          const res = await postAction(this.url.createEsignClmCompany, { id: id })
        if (res.success) {
          this.$message.success('认证成功!')
          this.loadData()
        }else{
          this.$message.error('认证失败!')
        }
      },
      handleCreateEdit(record){
        record.update = "N";
        this.handleEdit(record);
      },
      handleUpdateEdit(record){
        record.update = "Y";
        this.handleEdit(record);
      },
      handleSteps(id) {
      this.apprVisible = true
      getAction(this.url.getClmApproval, { bizEntityName: 'ClmCompany', bizEntityKey: id }).then((res) => {
        if (res.success) {
          let jsonStr = res.result.spRecord
          this.data2 = JSON.parse(jsonStr) //转换为json对象
          this.data2.forEach((record, index) => {
            record.id = index+1
            if (record.sp_status == '1') {
              record.statusName = ['审批中']
            } else if (record.sp_status == '2') {
              record.statusName = ['已同意']
            } else if (record.sp_status == '3') {
              record.statusName = ['已驳回']
            } else {
              record.statusName = ['已转审']
            }
          })
        }
      })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
